package com.wanmait.gohome.controller.web;

import com.github.pagehelper.PageInfo;
import com.wanmait.gohome.pojo.Clue;
import com.wanmait.gohome.pojo.Userinfo;
import com.wanmait.gohome.service.ClueService;
import com.wanmait.gohome.service.InformationService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/clue")
public class ClueController {
    @Resource
    private ClueService clueService;
    @Resource
    private InformationService informationService;


    @RequestMapping("remark")//添加评论
    @ResponseBody
    public void remark(String text, String rzid, HttpServletRequest request){
        Userinfo userinfo = (Userinfo) request.getSession().getAttribute("userinfo");
        int id=Integer.parseInt(rzid);
        Clue clue=new Clue();
        clue.setUserinfoId(userinfo.getId());
        clue.setInformationId(id);
        clue.setInfo(text);
        clueService.insertClue(clue);
        informationService.update(id);
    }



    @RequestMapping("informationListAll")//评论显示及分页
    public ModelAndView informationListAll(String id)
    {
        int ids=Integer.parseInt(id);
        System.out.print(id);
        PageInfo<Clue> clues = clueService.findAllById(ids);
        ModelAndView mv = new ModelAndView();
        mv.addObject("clues",clues);
        mv.setViewName("web/information/informationListAll");
        return mv;
    }

}
